﻿<Local:NavigationView
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="SeriesManager.View.SearchView"
    NavigationCacheMode="Enabled"
    
    xmlns:Local="using:SeriesManager.View"
    xmlns:Converter="using:SeriesManager.Converter"
    xmlns:Control="using:SeriesManager.Control">

    <Page.Resources>
        <Converter:DateStringConverter x:Key="DateStringConverter" />
        <Converter:BooleanVisibilityConverter x:Key="BooleanVisibilityConverter" />
        <Converter:EnumStringConverter x:Key="EnumStringConverter" />
        <Converter:TimeStringConverter x:Key="TimeStringConverter" />
    </Page.Resources>

    <Grid>
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        
        <GridView
            x:Name="gridView"
            Grid.RowSpan="2"
            Style="{StaticResource GridViewStyle}" 
            Padding="116,137,40,46"
            SelectionMode="None"
            Local:EventToCommandBehavior.RoutedEvent="ItemClick"
            Local:EventToCommandBehavior.Command="{Binding ItemClickedCommand}"
            ItemsSource="{Binding View}">
            <GridView.ItemContainerStyle>
                <Style TargetType="GridViewItem">
                    <Setter Property="Margin" Value="0,0,20,0"/>
                </Style>
            </GridView.ItemContainerStyle>
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Border Padding="14" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto" />
                                <RowDefinition Height="auto" />
                                <RowDefinition Height="auto" />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" />
                                <ColumnDefinition Width="600" />
                            </Grid.ColumnDefinitions>

                            <TextBlock Text="{Binding Name}" FontSize="26.667" Margin="0,0,0,20" FontWeight="Bold" TextWrapping="Wrap" Grid.ColumnSpan="2" />

                            <Image Source="{Binding Poster.LocalPath}" Height="600" Width="400" Stretch="UniformToFill" Margin="0,0,40,0" Grid.Row="1" Grid.RowSpan="3" />
                            
                            <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1">
                                <Border Background="#A30707" Padding="6">
                                    <TextBlock Foreground="White" Text="{Binding FirstAired, Converter={StaticResource DateStringConverter}, ConverterParameter=Year}" FontWeight="Bold" FontSize="20" />
                                </Border>
                                <Border Background="#A30707" Padding="6" Margin="10,0,0,0">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Foreground="White" Text="{Binding Runtime}" FontWeight="Bold" FontSize="20" />
                                        <TextBlock Foreground="White" Text=" min" FontWeight="Bold" FontSize="20" />
                                    </StackPanel>
                                </Border>
                                <Border Background="#A30707" Padding="6" Margin="10,0,0,0" Visibility="{Binding Active, Converter={StaticResource BooleanVisibilityConverter}}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Foreground="White" Text="{Binding AirDay, Converter={StaticResource EnumStringConverter}}" FontWeight="Bold" FontSize="20" Margin="0,0,6,0" />
                                        <TextBlock Foreground="White" Text="{Binding AirTime, Converter={StaticResource TimeStringConverter}}" FontWeight="Bold" FontSize="20" />
                                    </StackPanel>
                                </Border>
                                <Border Background="#A30707" Padding="6" Margin="10,0,0,0">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Foreground="White" Text="{Binding Seasons.Count}" FontWeight="Bold" FontSize="20" Margin="0,0,6,0" />
                                        <TextBlock Foreground="White" x:Uid="SeasonBox" FontWeight="Bold" FontSize="20" />
                                    </StackPanel>
                                </Border>
                                <Border Background="#A30707" Padding="6" Margin="10,0,0,0">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Foreground="White" Text="{Binding Count}" FontWeight="Bold" FontSize="20" Margin="0,0,6,0" />
                                        <TextBlock Foreground="White" x:Uid="EpisodeBox" FontWeight="Bold" FontSize="20" />
                                    </StackPanel>
                                </Border>
                            </StackPanel>

                            <ItemsControl ItemsSource="{Binding Genre}" Margin="0,10,0,0" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Column="1" Grid.Row="2">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border Background="#A30707" Padding="6" Margin="0,0,10,5">
                                            <TextBlock Foreground="White" Text="{Binding}" FontWeight="Bold" FontSize="20" />
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <Control:WrapPanel BlockSize="45" Orientation="Horizontal" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>
                            
                            <TextBlock Margin="0,20,0,0" Text="{Binding Overview}" FontSize="20" TextWrapping="Wrap" TextTrimming="WordEllipsis" LineHeight="24" Grid.Column="1" Grid.Row="3" />
                        </Grid>
                    </Border>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>

        <ListView
            x:Name="listView"
            Visibility="Collapsed"
            Style="{StaticResource ListViewStyle}"
            Grid.RowSpan="2"
            Padding="30,0"
            Margin="0,140,0,0"
            ItemsSource="{Binding View}"
            SelectionMode="None"
            Local:EventToCommandBehavior.RoutedEvent="ItemClick"
            Local:EventToCommandBehavior.Command="{Binding ItemClickedCommand}">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="Margin" Value="0,0,0,40" />
                    <Setter Property="Background" Value="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Margin="8">
                        <TextBlock Text="{Binding Name}" FontSize="26.667" Margin="0,0,0,20" FontWeight="Bold" TextWrapping="Wrap" />

                        <Control:WrapPanel BlockSize="45" Orientation="Horizontal" Margin="0,0,0,20">
                            <Border Background="#A30707" Padding="6">
                                <TextBlock Foreground="White" Text="{Binding FirstAired, Converter={StaticResource DateStringConverter}, ConverterParameter=Year}" FontWeight="Bold" FontSize="20" />
                            </Border>
                            <Border Background="#A30707" Padding="6" Margin="10,0,0,0">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Foreground="White" Text="{Binding Runtime}" FontWeight="Bold" FontSize="20" />
                                    <TextBlock Foreground="White" Text=" min" FontWeight="Bold" FontSize="20" />
                                </StackPanel>
                            </Border>
                            <Border Background="#A30707" Padding="6" Margin="10,0,0,0" Visibility="{Binding Active, Converter={StaticResource BooleanVisibilityConverter}}">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Foreground="White" Text="{Binding AirDay, Converter={StaticResource EnumStringConverter}}" FontWeight="Bold" FontSize="20" Margin="0,0,6,0" />
                                    <TextBlock Foreground="White" Text="{Binding AirTime, Converter={StaticResource TimeStringConverter}}" FontWeight="Bold" FontSize="20" />
                                </StackPanel>
                            </Border>
                            <Border Background="#A30707" Padding="6" Margin="10,0,0,0">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Foreground="White" Text="{Binding Seasons.Count}" FontWeight="Bold" FontSize="20" Margin="0,0,6,0" />
                                    <TextBlock Foreground="White" x:Uid="SeasonBox" FontWeight="Bold" FontSize="20" />
                                </StackPanel>
                            </Border>
                            <Border Background="#A30707" Padding="6" Margin="10,0,0,0">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Foreground="White" Text="{Binding Count}" FontWeight="Bold" FontSize="20" Margin="0,0,6,0" />
                                    <TextBlock Foreground="White" x:Uid="EpisodeBox" FontWeight="Bold" FontSize="20" />
                                </StackPanel>
                            </Border>
                        </Control:WrapPanel>

                        <ItemsControl ItemsSource="{Binding Genre}" Margin="0,0,0,20">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Background="#A30707" Padding="6" Margin="0,0,10,5">
                                        <TextBlock Foreground="White" Text="{Binding}" FontWeight="Bold" FontSize="20" />
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <Control:WrapPanel BlockSize="45" Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>

                        <Image Source="{Binding Poster.LocalPath, TargetNullValue=/Assets/SeasonViewBannerPlaceholder.png}" Height="300" Stretch="Uniform" />

                        <TextBlock Text="{Binding Overview}" FontSize="16" TextWrapping="Wrap" LineHeight="26" MaxLines="5" Margin="0,20,0,0" />
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <ProgressRing Width="200" Height="200" Foreground="{ThemeResource ApplicationForegroundThemeBrush}" IsActive="{Binding Loading}" Grid.Row="1" />

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            
            <AppBarButton Icon="Back" Height="95" Margin="10,46,10,0" Command="{Binding BackCommand}" Visibility="{Binding IsEnabled, Converter={StaticResource BooleanVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}"/>

            <StackPanel Margin="0,0,30,40" Grid.Column="1" IsHitTestVisible="False" VerticalAlignment="Bottom" HorizontalAlignment="Left" Orientation="Horizontal">
                <TextBlock x:Uid="SearchHeader" Style="{StaticResource HeaderTextBlockStyle}" TextWrapping="NoWrap" Margin="0,0,24,0" />
                <TextBlock Text="{Binding Name}" Style="{StaticResource HeaderTextBlockStyle}" TextWrapping="NoWrap" />
            </StackPanel>
        </Grid>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="Landscape768" />
                <VisualState x:Name="Landscape500">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="gridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="listView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Local:NavigationView>